using System;
using System.Collections.Generic;
using UnityEngine;

public class ButtonsColorsDataManager
{
	private string path = "DataFiles/buttons_colors";

	private INIParser ini = new INIParser();

	private string prefixBackgroundImagePath = "Images/BottleButtonsBackground/";

	private string prefixIconImagePath = "Images/BottleIcons/";

	private Dictionary<LiquidType, ButtonColorsData> colorsData;

	public ButtonsColorsDataManager()
	{
		LoadAllColors();
	}

	private void LoadAllColors()
	{
		LiquidType[] array = (LiquidType[])Enum.GetValues(typeof(LiquidType));
		colorsData = new Dictionary<LiquidType, ButtonColorsData>();
		TextAsset name = Resources.Load<TextAsset>(path);
		ini.Open(name);
		for (int i = 0; i < array.Length; i++)
		{
			LoadColorsForButton(array[i]);
		}
		ini.Close();
	}

	private void LoadColorsForButton(LiquidType type)
	{
		string text = type.ToString();
		if (!ini.IsSectionExists(text))
		{
			if (type != 0)
			{
				UnityEngine.Debug.Log("Nie istnieje sekcja dla przycisku =" + text);
			}
			return;
		}
		if (!ini.IsKeyExists(text, "background"))
		{
			UnityEngine.Debug.Log("Nie istnieje klucz o nazwie 'background' dla przycisku =" + text);
			return;
		}
		if (!ini.IsKeyExists(text, "icon"))
		{
			UnityEngine.Debug.Log("Nie istnieje klucz o nazwie 'icon' dla przycisku =" + text);
			return;
		}
		string backgroundSection = ini.ReadValue(text, "background", string.Empty);
		string iconSection = ini.ReadValue(text, "icon", string.Empty);
		ButtonColorsData buttonColorsData = LoadColorsFromIni(type, backgroundSection, iconSection);
		if (buttonColorsData != null)
		{
			colorsData.Add(type, buttonColorsData);
		}
	}

	private ButtonColorsData LoadColorsFromIni(LiquidType type, string backgroundSection, string iconSection)
	{
		if (!ini.IsSectionExists(backgroundSection))
		{
			if (type != 0)
			{
				UnityEngine.Debug.Log("Nie istnieje sekcja 'background' o nazwie = " + backgroundSection + " typ przycisku=" + type.ToString());
			}
			return null;
		}
		if (!ini.IsSectionExists(iconSection))
		{
			if (type != 0)
			{
				UnityEngine.Debug.Log("Nie istnieje sekcja 'icon' o nazwie = " + backgroundSection + " typ przycisku=" + type.ToString());
			}
			return null;
		}
		if (!ini.IsKeyExists(backgroundSection, "image_path"))
		{
			UnityEngine.Debug.Log("Nie istnieje klucz 'image_path' w sekcji " + backgroundSection + " typ przycisku=" + type.ToString());
			return null;
		}
		if (!ini.IsKeyExists(backgroundSection, "color_clicked"))
		{
			UnityEngine.Debug.Log("Nie istnieje klucz 'color_clicked' w sekcji " + backgroundSection + " typ przycisku=" + type.ToString());
			return null;
		}
		if (!ini.IsKeyExists(iconSection, "image_path"))
		{
			UnityEngine.Debug.Log("Nie istnieje klucz 'image_path' w sekcji " + iconSection + " typ przycisku=" + type.ToString());
			return null;
		}
		ButtonColorsData buttonColorsData = new ButtonColorsData();
		buttonColorsData.backgroundImagePath = prefixBackgroundImagePath + ini.ReadValue(backgroundSection, "image_path", string.Empty);
		Color color;
		bool flag = ColorUtility.TryParseHtmlString(ini.ReadValue(backgroundSection, "color_clicked", string.Empty), out color);
		buttonColorsData.iconColorClicked = color;
		buttonColorsData.iconImagePath = prefixIconImagePath + ini.ReadValue(iconSection, "image_path", string.Empty);
		if (!flag)
		{
			UnityEngine.Debug.Log("W sekcji= " + backgroundSection + " kolor jest niepoprawny");
			return null;
		}
		return buttonColorsData;
	}

	public ButtonColorsData GetColorDataForButton(LiquidType type)
	{
		if (colorsData.ContainsKey(type))
		{
			return colorsData[type];
		}
		return null;
	}
}
